import React, { Component } from 'react';
import SelectPath from '@/components/plugins/selectPath/index';
import ReactDOM from 'react-dom';
function sweet(options) {
  let container = document.createElement('div');
  ReactDOM.render(
    <LinkForm callback={options.callback} />
    , container
  )
}
class LinkForm extends Component {
  state = {
    isLoading: false,
  }
  componentDidMount() {
    this.showSelectPathModal();
  }

  onVideoChange = (item) => {
    const { callback } = this.props;
    let cdnUrl = window.cdnUrl;

    let _videoName = item.DisplayName;
    let _videoUrl = cdnUrl + '/' + item.Path;
    let _imgUrl;
    if (item.Img.length > 0) {
      _imgUrl = cdnUrl + '/' + item.Img;
    } else {
      _imgUrl = '';
    }

    let videoInfo = {
      videoImg: _imgUrl,
      videoName: _videoName,
      videoUrl: _videoUrl
    };
    videoInfo.html = `<p class="xkd-richtext-video"><video src="${videoInfo.videoUrl}" poster="${videoInfo.videoImg}" controls="" width="100%" > 正在加载</video></p>`
    callback(videoInfo)
    //this.props.onChange({ videourl: _videoUrl });
    this.videomodal.handleCancel();
  };
  selectPath = record => {
    const { callback } = this.props;
    let opt = {
      href: `${record.PagePath}`,
      textValue: record.PageName,
      target: '_blank',
    }
    //   record = { ...record, html: `<a href="${record.PagePath}" data-value=${record.PagePath}>${record.PageName}</a>` }
    callback(opt)
    this.close();
  };
  showSelectPathModal = () => {
    this.selectPathModal.showModal();
  };
  close = () => {
    this.selectPathModal.handleModalVisible();
  }
  selectRef = ref => {
    this.selectPathModal = ref;
  };
  render() {
    return (
      <SelectPath onRef={this.selectRef} selectPath={this.selectPath} />
    );
  }
}



export default function (options) {
  sweet(options);
}
